public class Solution513 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    int ans=-1;
    int max=0;

    public int findBottomLeftValue(TreeNode root) {
        dfs(root,1);
        return ans;
    }

    private void dfs(TreeNode root, int deep) {
        if (root==null){
            return;
        }
        if (deep>max){
            ans=root.val;
            max=deep;
        }
        dfs(root.left,deep+1);
        dfs(root.right,deep+1);
    }

    public static void main(String[] args) {
        System.out.println(new Solution513().findBottomLeftValue(new TreeNode(2,new TreeNode(1),new TreeNode(3))));
    }
}
